package com.healthsystem.portplay.controller;

import com.healthsystem.portplay.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
public class UpDateTimeController {
    private final UserDao userDao;

    @Autowired
    public UpDateTimeController(UserDao userDao) {
        this.userDao = userDao;
    }

    //    更新用户的时间状态
    @PutMapping("/updateTime")
    public String updateTime(
            @RequestBody UpdateTimeRequest request) {
        String username = request.getUsername();
        LocalDate newStartTime = request.getStartTime();
        LocalDate newEndTime = request.getEndTime();
        // 在这里根据用户名更新数据库中的用户时间
        userDao.updateUserTime(username, newStartTime, newEndTime);
        return "User Time updated successfully";

    }


    public static class UpdateTimeRequest {
        private String username;
        private LocalDate StartTime;
        private LocalDate EndTime;


        /**
         * 获取
         *
         * @return username
         */
        public String getUsername() {
            return username;
        }

        /**
         * 设置
         *
         * @param username
         */
        public void setUsername(String username) {
            this.username = username;
        }

        /**
         * 获取
         *
         * @return StartTime
         */
        public LocalDate getStartTime() {
            return StartTime;
        }

        /**
         * 设置
         *
         * @param StartTime
         */
        public void setStartTime(LocalDate StartTime) {
            this.StartTime = StartTime;
        }

        /**
         * 获取
         *
         * @return EndTime
         */
        public LocalDate getEndTime() {
            return EndTime;
        }

        /**
         * 设置
         *
         * @param EndTime
         */
        public void setEndTime(LocalDate EndTime) {
            this.EndTime = EndTime;
        }

        public String toString() {
            return "UpdateTimeRequest{username = " + username + "," +
                    " StartTime = " + StartTime + ", EndTime = " + EndTime + "}";
        }
    }
}
